//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/util/view_util.dart';

/// 章节tab 样式，首页二级标题
class ChapterTagDecoration extends Decoration {
  final bool isAtLast;

  const ChapterTagDecoration({required this.isAtLast});

  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return _ChapterTabPainter(this, isAtLast);
  }
}

class _ChapterTabPainter extends BoxPainter {
  final ChapterTagDecoration chapterTagDecoration;

  /// 是否是最后一个tab
  final bool isAtLast;

  _ChapterTabPainter(this.chapterTagDecoration, this.isAtLast);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    var size = configuration.size;

    double sizeW = isAtLast ? 5 : 43;

    /// 右下角x坐标
    double offsetX = offset.dx + size!.width - sizeW;

    /// 右下角y坐标
    double offsetY = offset.dy + size.height;

    Path path = Path()..moveTo(offsetX - 18, offsetY);
    path.lineTo(offsetX - 16, offsetY);
    path.quadraticBezierTo(offsetX, offsetY, offsetX, offsetY - 14);
    path.lineTo(offsetX, offsetY - 18);

    Paint paint = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = 4
      ..color = colorBlue1;

    canvas.drawPath(path, paint);
  }
}
